//
// Created by fengg on 2020/2/26.
//

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
using namespace std;

class Block{

public:
    Block* nextBlock;
    double coef;
    double expn;
};

class Multinomial {

private:
    Block* header;
    Block* tail;

public:
    Multinomial(){
        this->header = NULL;
        this->tail = NULL;
    }

    ~Multinomial(){
        Block* current = this->header;
        Block* next = current->nextBlock;
        while (current != NULL){
            free(current);
            current = next;
            if(next != NULL)
                next = next->nextBlock;
        }
    }

    Block* begin(){
        return this->header;
    }

    void pushItem(double coef, double expn){
        Block* temp = this->findExpn(expn);
        if(temp != NULL){
            temp->coef += coef;
            return;
        }
        Block* nextItem = (Block*)malloc(sizeof(Block));
        nextItem->coef = coef;
        nextItem->expn = expn;
        nextItem->nextBlock = NULL;
        if( this->header == NULL )
            header = nextItem;
        else
            tail->nextBlock = nextItem;
        tail = nextItem;
    }

    Block* getItem(int index){
        Block* current;
        current = this->header;
        for (int i = 1; i < index; ++i) {
            if(current == NULL)
                return NULL;
            current = current->nextBlock;
        }
        return current;
    }

    int inserItem(int pos, double coef, double expn){
        Block* arch =  this->getItem(pos);
        if (arch == NULL)
            return -1;
        Block* nextItem = arch->nextBlock;
        Block* current = (Block*)malloc(sizeof(Block));
        current->coef = coef;
        current->expn = expn;
        arch->nextBlock = current;
        current->nextBlock = nextItem;
        return 0;
    }
    int changeItem(int pos,  double coef, double expn){
        Block* current = this->getItem(pos);
        current->coef = coef;
        current->expn = expn;
        return 0;
    }

    int removeItem(int pos){
        Block* previous,*next;
        if (pos == 1){
            previous = header;
            header = header->nextBlock;
            free(previous);
            return 0;
        } else if (pos > 1){
            previous = this->getItem(pos-1);
            next = previous->nextBlock->nextBlock;
            free(previous->nextBlock);
            previous->nextBlock = next;
            return 0;
        }
    }

    Block* findExpn(double expn){
        Block* obs = header;
        while (obs != NULL){
            if (obs->expn == expn)
                return obs;
            obs = obs->nextBlock;
        }
        return NULL;
    }

    Multinomial* operator+=(Multinomial* y){

        Block *obs = y->begin();
        while (obs != NULL){
            Block* target = this->findExpn(obs->expn);
            if (target != NULL)
                target->coef += obs->coef;
            else{
                //this->pushItem(obs->coef,obs->expn);
                int count=1;
                for (Block* previous = this->header;
                     previous->expn > obs->expn;
                     previous = previous->nextBlock,count++);
                this->inserItem(count-1,obs->coef,obs->expn);

            }
            obs = obs->nextBlock;
        }

        return this;
    }

};

ostream& operator<<(ostream& os,Multinomial *x){
    bool header = true;
    for (Block* current = x->begin(); current != NULL; current= current->nextBlock) {
        if(current->coef == 0)
            continue;
        if(!header){
            if (current->coef == 1)
                os << '+';
            os << setiosflags(ios::showpos);

        } else {
            header = false;
        }
        switch ((int) current->coef){
            case -1:
                os << '-';
                break;
            case 1:
                break;
            default:
                os << current->coef;
        }

        os << resetiosflags(ios::showpos);
        if (current->expn > 1)
            os <<"x^" << current->expn;
        else if(current->expn == 1)
            os << 'x';
    }
    if (header){
        os << 0;
    }
    os << endl;
    return os;
}



int main(){
    Multinomial* x = new Multinomial();
    Multinomial* y = new Multinomial();
    double coef,expn;

    scanf("%lf,%lf",&coef,&expn);

    while (coef != 0 || expn != 0){
        x->pushItem(coef,expn);
        scanf("%lf,%lf",&coef,&expn);
    }
    scanf("%lf,%lf",&coef,&expn);
    while (coef != 0 || expn != 0){
        y->pushItem(coef,expn);
        scanf("%lf,%lf",&coef,&expn);
    }
    *x += y;
    cout << x;
    delete x;
    delete y;
    return 0;
}